package com.starlink.controller.admin;

import com.github.pagehelper.PageInfo;
import com.lop.open.api.sdk.domain.jdcloudprint.PullDataService.pullData.PrePrintDataInfo;
import com.starlink.client.jd.vo.PrintPullDataVO;
import com.starlink.common.WebResponse;
import com.starlink.common.annotation.WebAccess;
import com.starlink.model.request.mall.AdminMallLogisticsRequest;
import com.starlink.model.request.mall.AdminMallOrderListRequest;
import com.starlink.model.request.mall.MallCancelOrderRequest;
import com.starlink.model.request.mall.WechatRefund;
import com.starlink.model.vo.mall.AdminMallOrderDetailVO;
import com.starlink.model.vo.mall.AdminMallOrderListVO;
import com.starlink.model.vo.mall.WeixinRefundOrderVO;
import com.starlink.service.MallOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.SortDefault;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static com.starlink.common.enums.OperationTypeEnum.ADMIN_DAI_FA_HUO_PRICE;

/**
 * @Auther: zhouyuhang01
 * @Date: 2024/4/9 14:00
 * @Description: WechatBookOrderController
 * @Version 1.0.0
 */
@RestController
@RequestMapping("/admin/mallOrder")
@Api(value = "【管理端】商城订单模块", tags = {"【管理端】商城订单模块"})
public class AdminMallOrderController {

    @Autowired
    private MallOrderService orderService;

    @WebAccess(login = true)
    @ApiOperation("订单列表分页查询")
    @PostMapping("/pageList")
    public WebResponse<PageInfo<List<AdminMallOrderListVO>>> pageList(@SortDefault(sort = {"createTime"}, direction = Sort.Direction.DESC) Pageable pageable,
                                                                      @RequestBody AdminMallOrderListRequest request) {
        return WebResponse.build(orderService.pageList(request,pageable));
    }

    @WebAccess(login = true)
    @ApiOperation("订单详情查询")
    @PostMapping("/orderDetail")
    public WebResponse<AdminMallOrderDetailVO> orderDetail(@RequestBody AdminMallOrderListRequest request) {
        return WebResponse.build(orderService.orderDetail(request));
    }

    @WebAccess(login = true)
    @ApiOperation("订单发货")
    @PostMapping("/deliver_goods")
    public WebResponse<Boolean> deliverGoods(@RequestBody AdminMallLogisticsRequest request) {
        return WebResponse.build(orderService.deliverGoods(request));
    }

    @WebAccess(login = true)
    @ApiOperation("待付款状态下的取消订单")
    @PostMapping("/cancelOrder_waitPay")
    public WebResponse<Boolean> cancelOrderWaitPay(@RequestBody MallCancelOrderRequest request) {
        return WebResponse.build(orderService.cancelOrderWaitPay(request));
    }

    @WebAccess(login = true)
    @ApiOperation("取消已付款待发货订单")
    @PostMapping("/cancelOrder_isPay")
    public WebResponse<WeixinRefundOrderVO> cancelOrderIsPay(@RequestBody MallCancelOrderRequest request) {
        WechatRefund wechatRefund = new WechatRefund();
        wechatRefund.setOperationType(ADMIN_DAI_FA_HUO_PRICE.getType());
        return WebResponse.build(orderService.cancelOrderIsPay(request, wechatRefund));
    }

    @WebAccess(login = true)
    @ApiOperation("获取订单打印数据")
    @PostMapping("/getPullData")
    public WebResponse<PrintPullDataVO> getPullData(@RequestBody AdminMallOrderListRequest request) {
        return WebResponse.build(orderService.getPullData(request));
    }

}
